package com.yilin.medical.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.WindowManager;

public class JxDeviceUtil {
	public static int getScreenWidth(Context context){
		WindowManager wm = (WindowManager)context
                .getSystemService(Context.WINDOW_SERVICE); 
		return wm.getDefaultDisplay().getWidth();

	}
	public static int getScreenHeight(Context context){
		WindowManager wm = (WindowManager)context
                .getSystemService(Context.WINDOW_SERVICE); 
		return wm.getDefaultDisplay().getHeight();
	}
	/**
	 * <功能详细描述>判断网络是否可用<br>
	 * 
	 * @param context
	 * @return<br>
	 */
	public static boolean isNetworkAvailable(Context context) {
		ConnectivityManager connectivity = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (connectivity == null) {
		} else {
			NetworkInfo[] info = connectivity.getAllNetworkInfo();
			if (info != null) {
				for (int i = 0; i < info.length; i++) {
					if (info[i].getState() == NetworkInfo.State.CONNECTED) {
						return true;
					}
				}
			}
		}
		return false;
	}
	
	/**
	 * 
	  * 方法描述		获取设备ID
	  * create: 2014-8-28下午2:12:23
	  * @param model 参数描述
	  * @return 返回值描述
	 */
	public static String getDeviceId(Context context){
		String deviceId = "";
		TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		String tmDeviceId = tm.getDeviceId();
		if(null != tmDeviceId &&!TextUtils.isEmpty(tmDeviceId)){
			deviceId = tmDeviceId;
		}else{
			deviceId = JxLocalSharedFileUtils.getMTDeviceId(context);
		}
		JxLogUtil.d("device id is ....: "+deviceId);
		return deviceId;
	}
}
